using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;
using Core.Graphics;
using Core.Graphics.Layers;

namespace Core.Mapping
{
    /// <summary>Contains list of the different kinds of Layers</summary>
    public enum MapLayerTypes
    {
        Base = 0,
        Terrain = 1,
        TerrainDetail = 2,
        TerrainSuperDetail = 3,
        Collection = 4,
    }

    public enum MapLayerBaseTypes
    {
        Base = 0,
        Terrain = 1,
        Collection = 2,
    }

    [Serializable()]
    [DefaultPropertyAttribute("MapLayer")]
    [XmlRoot("MapLayer")]
    public class MapLayer : TileLayer, IXmlSerializable
    {
        [XmlAttribute("LayerType")]
        public MapLayerTypes Type { get { return _LayerType; } set { _LayerType = value; } }

        protected MapLayerTypes _LayerType;

        public MapLayer(MapLayerTypes type, TileCollection tiles) : base(tiles, Map.MapWidth, Map.MapHeight)
        {
            _LayerType = type;
        }

        public MapLayer(MapLayerTypes type)
            : base(Map.MapWidth, Map.MapHeight)
        {
            _LayerType = type;
        }

        public MapLayer()
        {
            //For XML Serialization
        }

        #region IXmlSerializable Members

        System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
        {
            return null;
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            _LayerType = (MapLayerTypes)Enum.Parse(typeof(MapLayerTypes), reader.GetAttribute("LayerType"));

            base.ReadXml(reader);
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            //Write Layer Type Attribute
            writer.WriteAttributeString("LayerType", _LayerType.ToString());

            base.WriteXml(writer);
        }

        #endregion
    }

    public class MapLayerCollection : Collection<MapLayer> { }

}
